home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / mosmllib / test / date.sml < prev    next >
Encoding:
Text File  |  1997-08-18  |  2.9 KB  |  77 lines  |  [TEXT/R*ch]

  1. (* test/date.sml
  2.    PS 1995-03-20, 1995-05-12, 1996-07-05
  3. *)
  4.  
  5. use "auxil.sml";
  6.  
  7. local
  8.     open Time Date 
  9.     fun date h = 
  10.     toString(fromTime(now() + fromReal (3600.0 * real h))) ^ "\n";
  11.     fun nowdate () = Date.fromTime(now());
  12.     fun mkdate(y,mo,d,h,mi,s) =
  13.     DATE {year=y, month=mo, day=d, hour=h, minute=mi, second=s, 
  14.           wday=SOME Fri, yday=SOME 5, isDst=NONE}
  15.     fun cmp(dt1, dt2) = compare(mkdate dt1, mkdate dt2)
  16.  
  17.     fun fromto dt = 
  18.     toString (valOf (fromString (toString dt))) = toString dt
  19.  
  20.     fun tofrom s = 
  21.     toString (valOf (fromString s)) = s
  22. in
  23.     
  24. val _ = 
  25.     (print "This is now:                    "; print (date 0);
  26.      print "This is an hour from now:       "; print (date 1);
  27.      print "This is a day from now:         "; print (date 24);
  28.      print "This is a week from now:        "; print (date 168);
  29.      print "This is 120 days from now:      "; print (date (24 * 120));
  30.      print "This is 160 days from now:      "; print (date (24 * 160));
  31.      print "This is 200 days from now:      "; print (date (24 * 200));
  32.      print "This is 240 days from now:      "; print (date (24 * 240));
  33.      print "This is the epoch (UTC):        "; 
  34.      print (toString(fromUTC zeroTime) ^ "\n");   
  35.      print "This is the number of the day:  "; 
  36.      print (fmt "%j" (nowdate()) ^ "\n");
  37.      print "This is today's weekday:        ";
  38.      print (fmt "%A" (nowdate()) ^ "\n");
  39.      print "This is the name of this month: ";
  40.      print (fmt "%B" (nowdate()) ^ "\n"));
  41.  
  42. val test1 = 
  43. check'(fn _ => 
  44.                cmp((1993,Jul,25,16,12,18), (1994,Jun,25,16,12,18)) = LESS
  45.        andalso cmp((1995,May,25,16,12,18), (1994,Jun,25,16,12,18)) = GREATER
  46.        andalso cmp((1994,May,26,16,12,18), (1994,Jun,25,16,12,18)) = LESS
  47.        andalso cmp((1994,Jul,24,16,12,18), (1994,Jun,25,16,12,18)) = GREATER
  48.        andalso cmp((1994,Jun,24,17,12,18), (1994,Jun,25,16,12,18)) = LESS
  49.        andalso cmp((1994,Jun,26,15,12,18), (1994,Jun,25,16,12,18)) = GREATER
  50.        andalso cmp((1994,Jun,25,15,13,18), (1994,Jun,25,16,12,18)) = LESS
  51.        andalso cmp((1994,Jun,25,17,11,18), (1994,Jun,25,16,12,18)) = GREATER
  52.        andalso cmp((1994,Jun,25,16,11,19), (1994,Jun,25,16,12,18)) = LESS
  53.        andalso cmp((1994,Jun,25,16,13,17), (1994,Jun,25,16,12,18)) = GREATER
  54.        andalso cmp((1994,Jun,25,16,12,17), (1994,Jun,25,16,12,18)) = LESS
  55.        andalso cmp((1994,Jun,25,16,12,19), (1994,Jun,25,16,12,18)) = GREATER
  56.        andalso cmp((1994,Jun,25,16,12,18), (1994,Jun,25,16,12,18)) = EQUAL);
  57.  
  58. val test2 = 
  59.     check'(fn _ => 
  60.        fmt "%A" (mkdate(1995,May,22,4,0,1)) = "Monday");
  61.  
  62. val test3 = 
  63.     check'(fn _ => 
  64.        List.all fromto 
  65.        [mkdate(1995,Aug,22,4,0,1),
  66.         mkdate(1996,Apr, 5, 0, 7, 21),
  67.         mkdate(1996,Mar, 5, 6, 13, 58)]);
  68.  
  69. val test4 = 
  70.     check'(fn _ => 
  71.        List.all tofrom 
  72.        ["Fri Jul  5 14:25:16 1996",
  73.        "Mon Feb  5 04:25:16 1996",
  74.        "Sat Jan  6 04:25:16 1996"])
  75.     
  76. end
  77.